package com.itbaizhan.shopping_order_customer_api.controller;


import com.itbaizhan.shopping_common.pojo.Orders;
import com.itbaizhan.shopping_common.result.BaseResult;
import com.itbaizhan.shopping_common.service.OrderService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/user/orders")
public class OrderController {

    @DubboReference
    private OrderService orderService;

    @PostMapping("/add")
    public BaseResult<Orders> add(@RequestHeader Long userId,@RequestBody Orders orders) {
        orders.setUserId(userId);
        orderService.add(orders);
        return BaseResult.ok(orders);
    }

    @GetMapping("/findById")
    public BaseResult<Orders> findById(String id) {
        Orders orders = orderService.findById(id);
        return BaseResult.ok(orders);
    }

    @GetMapping("/findUserOrders")
    public BaseResult<List<Orders>> findUserOrders(@RequestHeader Long userId,Integer status) {
        List<Orders> orders = orderService.findByUserId(userId,status);
        return BaseResult.ok(orders);
    }


}
